<?php

namespace app\admin\model;

use think\Model;


class Packages extends Model
{

    

    

    // 表名
    protected $name = 'packages';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'cate_id_text',
        'status_text',
        'platform_type_text',
        'bxhf_text',
        'card_type_text'
    ];
    

    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
        });
    }

    public function getIsExtendList()
    {
        return ['1' => __('Is_extend 1'), '2' => __('Is_extend 2')];
    }

    public function getCateIdList()
    {
        return ['1' => __('电信'), '2' => __('联通'), '3' => __('移动'),'4' => __('广电'),'5' => __('宽带'),'6' => __('纯激活')];
    }

    public function getStatusList()
    {
        return ['1' => __('Status 1'), '2' => __('Status 2')];
    }

    public function getPlatformList(){
        return ['1' => __('Platform_type 1'), '2' => __('Platform_type 2'),'3' => __('Platform_type 3')];
    }

    public function getDayList(){
        return ['1' => __('当日'), '2' => __('次日'),'3' => __('第三日'),'4' => __('第四日'),'5' => __('第五日'),'6' => __('次月30日')];
    }

    public function getCateIdTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['cate_id']) ? $data['cate_id'] : '');
        $list = $this->getCateIdList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPlatformTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['platform_type']) ? $data['platform_type'] : '');
        $list = $this->getPlatformList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getCardTypeList(){
        return ['1' => __('充值版'), '2' => __('激活版')];
    }

    public function getCardTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['card_type']) ? $data['card_type'] : '');
        $list = $this->getCardTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getBxhfTextAttr($value, $data)
    {
        $value = 0;
        if(isset($data['epact_set_meal']) && isset($data['ciyue_set_meal']) && $data['epact_set_meal'] > 0){
            $jie_day = date('d');
            if($jie_day > 30){
                $jie_day = 30;
            }
            $value = round((30 - $jie_day)*($data['epact_set_meal']/30));
            if($value < 10){
                $value = 10;
            }
        }
        return $value;
    }


}
